package com.czl.module_storehouse.adapter;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.czl.base.data.bean.tengyun.ReceiveBean;
import com.czl.module_storehouse.R;
import com.czl.module_storehouse.bean.RemandBean;
import com.lihang.ShadowLayout;

import java.util.List;

/**
 * @author xubin
 */
public class RemandHomeReceiveAdapter extends BaseQuickAdapter<RemandBean, BaseViewHolder> {

    public RemandHomeReceiveAdapter(int layoutResId, @Nullable List<RemandBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, RemandBean item) {
        ReceiveBean receiveBean = item.getReceiveBean();
        if (receiveBean != null) {
            helper.setText(R.id.tv_title, receiveBean.getReceiveName())
                    .setText(R.id.tv_date, receiveBean.getReceiveDate())
                    .setText(R.id.tv_code, receiveBean.getReceiveCodeTitle("领用单："))
                    .setText(R.id.tv_department, "领用部门：" + receiveBean.getReceivePersonDepartment())
                    .setText(R.id.tv_desc, "领用说明：" + receiveBean.getApplyComment())
                    .setVisible(R.id.tv_remand_total, receiveBean.isRemandVisableNum(false))
                    .setText(R.id.tv_remand_total, receiveBean.getRemandTotalTextNum("已还"));
            ShadowLayout shadowLayout = helper.getView(R.id.shadowLayout);
            shadowLayout.setShadowHiddenBottom(helper.getLayoutPosition() != getDefItemCount() - 1);
            helper.setVisible(R.id.tv_remand_total, receiveBean.getTotalDamageNumInt() > 0)
                    .setText(R.id.tv_remand_total, getContext().getString(R.string.damage_placeholder, receiveBean.getTotalDamageNum()));
            helper.getView(R.id.tv_remand_total).setOnClickListener(v -> {
                if (getOnItemChildClickListener() != null) {
                    getOnItemChildClickListener().onItemChildClick(RemandHomeReceiveAdapter.this, v, helper.getAbsoluteAdapterPosition());
                }
            });
        }
    }
}
